import { globalUrl } from "./../config";
import { BaseService } from "./BaseServices";
import { service } from "@/library/injector";
import { proj, env } from "@/config";
import { logger } from "@/utils/logger";



@service
export class MiniService extends BaseService {
  /* 获取广告id接口 */
  private readonly API_MINI_CONFIG: string = "http://192.168.1.244:5000/api/Config";
  private readonly API_USER_CONFIG: string = "http://192.168.1.244:5000/api/User";
  private readonly API_AD_SUBMIT: string = "http://192.168.1.244:5000/api/User/playad";
  private readonly API_ANCHOR_DATA: string = "http://192.168.1.244:5000/api/Anchor";
  private readonly API_ANCHOR_VOTE: string = "http://192.168.1.244:5000/api/User/HeartVote";


  /**
   * 获取广告id
   */
  async getMiniConfig(): Promise<any> {
    try {
      let res = await this.request.get(this.API_MINI_CONFIG, { mp: proj, env });
      return res.data.data;
    } catch (err) {
      logger.error(`[fail] - getMiniConfig`, err);
      throw err; // 此处考虑errCode,完全返回错误对象
    }
  }
  /**
   * 获取用户信息
   */
  async getUserConfig(): Promise<any> {
    try {
      let res = await this.request.get(this.API_USER_CONFIG, { mp: proj, env });
      return res.data.data;
    } catch (err) {
      logger.error(`[fail] - getUserConfig`, err);
      throw err; // 此处考虑errCode,完全返回错误对象
    }
  }
  /**
   * 关闭广告提交
   */
  async AdSubmit(isEnd: boolean) {
    try {
      let res = await this.request.post(this.API_AD_SUBMIT, { mp: proj, env, isEnd });
      return res.data.data;
    } catch (err) {
      logger.error(`[fail] - AdSubmit`, err);
      throw err;
    }
  }
  /**
 * rank数据
 */
  async anchorData() {
    try {
      let res = await this.request.get(this.API_ANCHOR_DATA, { mp: proj, env });
      return res.data.data;
    } catch (err) {
      logger.error(`[fail] - anchorData`, err);
      throw err;
    }
  }

  /**
* rank数据
*/
  async voteAnchor() {
    try {
      let res = await this.request.post(this.API_ANCHOR_VOTE, { mp: proj, env });
      if (res.data.success) {
        return res.data
      }
    } catch (err) {
      logger.error(`[fail] - anchorData`, err);
      throw err;
    }
  }
}
